﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevelopmentPFR.Utilitaire;


namespace DevelopmentPFR.Plateforme_Stockage
{
    public partial class BonsReceptions : System.Web.UI.Page
    {
        private List<string> codesArticle = new List<string>(); 
        protected void Page_Load(object sender, EventArgs e)
        {
            //Chargement de la liste des articles selon la réference commande
            string _referenceCa = Request["ref"];
            DataTable detailCa = BaseDeDonnees.ExecuteSelectStoredProcedure("spPs_detailBonCommande", new Hashtable()
                {
                    {"@refCommandeCa", _referenceCa}
                });
            
            if (!IsPostBack)
            {
                listeProduits.DataSource = detailCa;
                listeProduits.DataBind();
            }
            //Chargement des données. 
            LoadData(detailCa.Select("").First());
            LoadCodeArticle();

            foreach (GridViewRow row in listeProduits.Rows)
            {
                ((Button)row.FindControl("quantiteRecu")).ID = "quantiteRecu" + row.Cells[0].Text;
            }
            
        }
        private void LoadData(DataRow row)
        {
            refCommandeCa.Text = (string)row["refCommandeCa"];
            fournisseur.Text = (string)row["nomFournisseur"];
            dateCommande.Text = ((DateTime)row["dateCommandeCa"]).ToShortDateString();
            statut.Text = (string)row["statut"];
            prixTotalHT.Text = ((double)row["prixHtTotal"]).ToString();
        }

        private void LoadCodeArticle()
        {
            foreach (GridViewRow row in listeProduits.Rows)
            {
                codesArticle.Add(row.Cells[0].Text);
            }
        }

        protected void AssignJavaScriptToButton(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((Button)e.Row.FindControl("quantiteRecu")).Attributes.Add("onclick", "javascript:pressButton(" + e.Row.RowIndex + "); return false;");
            }
        }
    }
}

